package com.kld.amaptset.conn;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by KELUNGDE on 2017/8/5.
 */

public class Gank {

    public static final String HOST="http://gank.io/api/";
    private static API api;
    protected static final  Object lock=new Object();
    private static Retrofit retrofit;
    private Gank(){}

    static {
        Gson gson=new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
                .create();
        retrofit=new Retrofit.Builder()
                .baseUrl(HOST)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }

    public  static  API getGankRetrofitInstance(){
        synchronized (lock){
            if (api==null){
                api=retrofit.create(API.class);
            }
            return api;
        }
    }

}


